//
//  ViewController.m
//  iCloudBackUps
//
//  Created by razeen on 12/18/15.
//  Copyright © 2015 razeen. All rights reserved.
//

#define CLOUD_CONTAINER_ID  @"iCloud.com.trustasia.t-shield"


#import "ViewController.h"
#import "iCloud.h"
#import "FMDB.h"
#import "DBService.h"
#import "UserModel.h"

#import "NSMetadataItem+sonson.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *appName;
@property (weak, nonatomic) IBOutlet UITextField *account;
@property (weak, nonatomic) IBOutlet UITextField *sercet;
@property (strong, nonatomic) UserModel *userModel;


- (IBAction)commit:(id)sender;

@end

@implementation ViewController



- (void)viewDidLoad {
    
    [super viewDidLoad];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)commit:(id)sender {
    
    _userModel = [[UserModel alloc]init];
    
    _userModel.appName = _appName.text;
    _userModel.userAccount = _account.text;
    _userModel.userkey = _sercet.text;
    
    [[DBService shareDB] addAccountWithModel:_userModel];
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"savetocloud" object:nil];
        
    }];
    
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    UITouch *oneTouch = [touches anyObject];
    
    CGPoint point = [oneTouch locationInView:self.view];
    
    if(!CGRectContainsPoint(_appName.frame, point)) {
        
        [_appName resignFirstResponder];
    }
    if (!CGRectContainsPoint(_account.frame, point)) {
        
        [_account resignFirstResponder];
    }
    if (!CGRectContainsPoint(_sercet.frame, point)) {
    
        [_sercet resignFirstResponder];
    }
}


@end
